package net.huashitong.supervision.task.service;

import com.sirdc.modules.core.dao.BaseDao;
import com.sirdc.modules.sys.base.StringPKService;
import com.sirdc.modules.sys.service.SysTableService;
import net.huashitong.supervision.task.dao.TaskLogNewDao;
import net.huashitong.supervision.task.entity.TaskCategory;
import net.huashitong.supervision.task.entity.TaskLogNew;
import net.huashitong.supervision.task.util.HolidayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ling
 * Date: 2019/8/19
 * Time: 20:23
 * To change this template use File | Settings | File Templates.
 * Description:
 */
@Service
public class TaskLogNewService extends StringPKService<TaskLogNew> {
    @Autowired
    private TaskLogNewDao taskLogNewDao;
    @Autowired
    private SysTableService tableService;
    @Override
    protected BaseDao<TaskLogNew, String> getDao() {
        return taskLogNewDao;
    }

    @Override
    protected void beforeSave(TaskLogNew obj) {
        obj.setSysId(tableService.updateMaxSysId("t_task_log_new",null ));
    }

    public void save(TaskLogNew TaskLogNew, String userId){
        Date date = new Date();
        String date1 = HolidayUtils.sdf1.format(date);
        String time = HolidayUtils.sdf2.format(date);
        TaskLogNew.setSysId(tableService.updateMaxSysId("t_task_log_new",null));
        TaskLogNew.setCreateUser(userId);
        TaskLogNew.setUpdUser(userId);
        TaskLogNew.setCreateDate(date1);
        TaskLogNew.setCreateTime(time);
        TaskLogNew.setUpdDate(date1);
        TaskLogNew.setUpdTime(time);
        getDao().save(TaskLogNew);
    }
    public List<TaskLogNew> getByUnitId(String taskUnitId) {
        return taskLogNewDao.getByUnitId(taskUnitId);
    }

    public void deleteByUnitIds(List<String> taskUnitIds) {
        taskLogNewDao.deleteByUnitIds(taskUnitIds);
    }
}
